﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class shop_Article_Manager : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {            
            InitComponents();
            ReadAction();
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页        

        base.OnLoad(e);
    }

    #endregion

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string sType = hType.Value;

        Response.Redirect("Article_Edit.aspx?Action=Add&Type=" + sType);
    }

    protected void btnEdit_Click(object sender, EventArgs e)
    {
        string ID = this.hID.Value;
        string sType = hType.Value;

        if (ID != "")
        {
            Response.Redirect("Article_Edit.aspx?Action=Edit&Type=" + sType + "&ID=" + ID + "");
        }
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        long ID = Shove._Convert.StrToLong(hID.Value, 0);

        long i = new DAL.Tables.tbl_Site_Article().Delete("ID=" + ID.ToString());

        if (i >= 0)
        {
            Shove._Web.JavaScript.Alert(this.Page, "删除成功！");
        }
        else
        {
            Shove._Web.JavaScript.Alert(this.Page, "删除失败！");
        }

        BindData();
    }

    protected void uwgMain_PageIndexChanged(object sender, Infragistics.WebUI.UltraWebGrid.PageEventArgs e)
    {
        BindData();
    }

    private void InitComponents()
    {
        Utility.InitUltraWebGrid.InitDisplayLayOut(this.uwgMain);
    }

    private void ReadAction()
    {
        //Type:1 商城公告 2 购物指南 3付款方式 4 帮助中心 5常见问题

        string sType = Shove._Web.Utility.GetRequest("Type");
        hType.Value = sType;

        if (sType == "SCGG")
        {
            pTitle.Header.Text = "商城公告";
        }
        else if (sType == "GWZN")
        {
            pTitle.Header.Text = "购物指南";
        }
        else if (sType == "FKFS")
        {
            pTitle.Header.Text = "付款方式";
        }
        else if (sType == "BZZX")
        {
            pTitle.Header.Text = "帮助中心";
        }
        else if (sType == "CJWT")
        {
            pTitle.Header.Text = "常见问题";
        }
    }

    private void BindData()
    {
        //Type:1 商城公告 2 购物指南 3付款方式 4 帮助中心 5常见问题
        string Condtion = "ShopID = " + _Site.ID;

        string sType = hType.Value;

        if (sType == "SCGG")
        {
            Condtion += " and ArticleTypeID = 1";
        }
        else if (sType == "GWZN")
        {
            Condtion += " and ArticleTypeID = 2";
        }
        else if (sType == "FKFS")
        {
            Condtion += " and ArticleTypeID = 3";
        }
        else if (sType == "BZZX")
        {
            Condtion += " and ArticleTypeID = 4";
        }
        else if (sType == "CJWT")
        {
            Condtion += " and ArticleTypeID = 5";
        }

        uwgMain.DataSource = new DAL.Tables.tbl_Site_Article().Open("", Condtion, "");
        uwgMain.DataBind();


        //清除html标签 ，截取纯文本字符串
        for (int i = 0; i < uwgMain.Rows.Count; i++)
        {
            string s = uwgMain.Rows[i].Cells[2].Text.Trim();
            uwgMain.Rows[i].Cells[2].Text = System.Text.RegularExpressions.Regex.Replace(s, "<[^>]+>", "");
        }
    }
}
